/*
 * Name 		: Chang Hyun Park
 * Student ID	: 2007******
 * Major		: Computer Engineering
 * Year			: 3rd Year
 * Subject		: File Management
 * Filename		: freemanager.c
 */

#include "header.h"

void freemem(char* filename, int* filedata, node* head, int* lru_buf,
												int* mru_buf, int** lfu_buf)
{//Memory leak is prevented by actually keeping track of all malloc()ed address
	int i=0;
	node* temp, *temp2;

	free(filename);
	free(filedata);

	//free linked List!!
	temp=head->next;
	temp2=temp;
	for(i=0;i<buffer_size-1;i++)	//Run buffer_size-1 times
	{
		temp2=temp->next;
		free(temp);
		temp=temp2;
	}//Free head alone, because in the end there will be reference problems
	free(head);

	//Free Arrays
	free(lfu_buf[0]);
	free(lfu_buf[1]);
	free(lfu_buf);
	free(lru_buf);
	free(mru_buf);
}
